using System;
using System.Linq;
using System.Linq.Expressions;
using NHibernate.Linq;
using ThunderJob.Domain.PersistenceInterfaces;
using ThunderJob.Domain.Specifications;

namespace ThunderJob.Persistence.Repositories
{
    public class LinqRepository<T> : Repository<T>, ILinqRepository<T>
    {
        public T Obtener(ILinqSpecification<T> specification)
        {
            return this.Session.Linq<T>().Where(specification.Predicate).SingleOrDefault();
        }

        public IQueryable<T> ObtenerTodos()
        {
            return this.Session.Linq<T>().AsQueryable();
        }

        public IQueryable<T> ObtenerTodos(ILinqSpecification<T> specification)
        {
            return this.Session.Linq<T>().Where(specification.Predicate);
        }


    }
}